package com.grep.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.grep.base.util.PinYin4jUtil;
import com.grep.base.util.UUIDGenerator;
import com.grep.extra.dao.impl.TaskDAOSQL;
import com.grep.extra.dao.impl.WebSiteDAOSQL;
import com.grep.extra.factory.utils.JsoupUtil;
import com.grep.web.tool.GrepTest;
import com.grep.web.tool.Target;

/**
 * Servlet implementation class NewSiteTask
 */
public class JsoupTestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		
		String siteUrl = request.getParameter("site_url");
		String jsoupExp = request.getParameter("jsoup_exp"); 
		System.out.println(siteUrl);
		System.out.println(jsoupExp);
		JsoupUtil jsouputil = new JsoupUtil(siteUrl);
		List<String> result = jsouputil.getURLSByPath(jsoupExp);
		String retXml = "";
		for(String str : result){
			retXml = retXml+str+"</br>";
		}
		response.getWriter().write(retXml);
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

}
